package recycle.controller;

import com.sun.org.apache.xpath.internal.operations.Or;
import recycle.pojo.Ordermaster;
import recycle.service.OrdermasterService;
import recycle.utils.Page;
import recycle.vo.OrdermasterParam;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.dubbo.config.annotation.Reference;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 描述：订单主表 控制器
* @author 孙冉
* @date 2019/07/22
*/
@RestController
@RequestMapping("/ordermaster")
public class OrdermasterController{
	@Resource
	private OrdermasterService ordermasterService;
 	
 	@RequestMapping("/findById.json")
    public Ordermaster findById(Integer orderId){
        Ordermaster result = null;
        try {
            result = ordermasterService.findById(orderId);
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;
    }

    /**
     * 描述：获取所有的Ordermaster对象
     */
    @RequestMapping("/findAll.json")
    public List<Ordermaster> findAll(){
        List<Ordermaster> result = null;
        try {
            result = ordermasterService.findAll();
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;
    }

    /**
     * 描述：新增保存Ordermaster对象
     */
    @RequestMapping("/save.json")
    public Map save(Ordermaster ordermaster){
        Map result = new HashMap();
        result.put("flag",false);
        result.put("msg","保存订单主表失败");
        try {
            if(ordermasterService.save(ordermaster)>0){
                result.put("flag",true);
                result.put("msg","保存订单主表成功");
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;
    }

    /**
     * 描述：根据主键删除订单主表对象
     * @param orderId
     */
    @RequestMapping("/delete.json")
    public Map delete(Integer orderId){
        Map result = new HashMap();
        result.put("flag",false);
        result.put("msg","保存订单主表失败");
        try {
            if(ordermasterService.delete(orderId)>0){
                result.put("flag",true);
                result.put("msg","保存订单主表成功");
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;
    }

    /**
     * 描述：更新订单主表对象
     */
    @RequestMapping("/update.json")
    public Map update(Ordermaster ordermaster){
        Map result = new HashMap();
        result.put("flag",false);
        result.put("msg","更新订单主表失败");
        try {
            if( ordermasterService.update(ordermaster)>0){
                result.put("flag",true);
                result.put("msg","更新订单主表成功");
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;

    }

    /**
     * 根据不确定的条件，动态查询
     */
    @RequestMapping("/query.json")
    public List<Ordermaster> query(OrdermasterParam param){
        List<Ordermaster> result = null;
        try {
            result = ordermasterService.query(param);
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;
    }

    /**
     * 根据不确定的条件，动态分页查询
     */
    @RequestMapping("/queryByPage.json")
    public Page queryByPage(OrdermasterParam param){
        Page result = null;
        try {
            result = ordermasterService.queryByPage(param);
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;
    }


    @RequestMapping("/selectByInData.do")
   public List<Ordermaster> selectByInData(Date inData){


        List<Ordermaster> list= ordermasterService.selectByInData(inData);


        for (int i = 0; i <list.size() ; i++) {
            Ordermaster ordermaster = list.get(i);
            if(ordermaster.getRecycleMethod()==1){
                ordermaster.setOther1("上门回收");
            }else if(ordermaster.getRecycleMethod()==2){
                ordermaster.setOther1("邮寄");
            }
        }

        return list;
   }
 }
